package com.wyp.didishige.fragment.register;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wyp.didishige.R;
import com.wyp.didishige.activity.PoiSearchActivity;
import com.wyp.didishige.activity.RegisterQQActivity;
import com.wyp.didishige.fragment.FragmentBase;
import com.wyp.didishige.utils.IntentUtil;
import com.wyp.didishige.utils.StringUtils;
import com.wyp.didishige.utils.ToastUtil;

/**
 * 注册：设置小区生活信息
 */
public class RegisterQQStep2 extends FragmentBase implements View.OnClickListener {


    /**签名*/
    /**
     * 几幢
     */
    private AppCompatEditText user_build;
    /**
     * 房号
     */
    private AppCompatEditText user_house;
    /**
     * 生活圈
     */
    private AppCompatEditText user_lifeCircle;
    /**
     * 工作圈
     */
    private AppCompatEditText user_workCircle;
    /**
     * 家乡
     */
    private AppCompatEditText user_hometown;

    /**
     * 小区
     */
    private TextView user_community;

    /**
     * 选择小区区域
     */
    private LinearLayout lay_user_community;
    private  View view;
    public RegisterQQStep2() {
        super();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.register_step_2, container, false);
        init();
        return view;
    }

    @Override
    protected void initWidget() {
        super.initWidget();
        user_community = (TextView) view.findViewById(R.id.user_community);
        user_build = (AppCompatEditText) view.findViewById(R.id.user_build);
        user_house = (AppCompatEditText) view.findViewById(R.id.user_house);
        user_lifeCircle = (AppCompatEditText) view.findViewById(R.id.user_lifeCircle);
        user_workCircle = (AppCompatEditText) view.findViewById(R.id.user_workCircle);
        user_hometown = (AppCompatEditText) view.findViewById(R.id.user_hometown);
        lay_user_community = (LinearLayout) view.findViewById(R.id.lay_user_community);
    }

    @Override
    protected void initWidgetListener() {
        super.initWidgetListener();
        final RegisterQQActivity activity= (RegisterQQActivity) getActivity();
        lay_user_community.setOnClickListener(this);

        user_hometown.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                activity.registerUser.setUserHometown(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        user_workCircle.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                activity.registerUser.setWorkCircle(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        user_lifeCircle.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                activity.registerUser.setLifeCircle(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        user_house.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                activity.registerUser.setHouse(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
        user_build.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                activity.registerUser.setBuild(s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }

    /**
     * 设置小区
     * @param community
     */
    public void setUserCommunity(String community){
        final RegisterQQActivity activity= (RegisterQQActivity) getActivity();
        user_community.setText(community);
        activity.registerUser.setCommunity(community);
    }
    public boolean verfiy3(){

        if (StringUtils.isNullOrEmpty(user_community.getText().toString())){
            ToastUtil.showShort(getActivity(),"填写您居住小区或者地点");
            return false;
        }

        return true;
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.lay_user_community:
                Bundle bundle = new Bundle();
                bundle.putString(PoiSearchActivity.ADDRESS, "");
                IntentUtil.start_activity_for_result(getActivity(), PoiSearchActivity.class, RegisterQQActivity.SET_COMMUNITY_CODE, bundle);
                break;
        }
    }
}
